home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
Book Chapters
/
13 - PowerPC
/
Optimize 1
/
Blitter.c
next >
Wrap
Text File
|
1995-03-05
|
2KB
|
87 lines
/*********************/
/* BLITTER.C */
/*********************/
//
// This file contains the "poor man's profiler" and
// the screen blitter routine.
//
/****************************/
/* EXTERNALS */
/****************************/
extern Ptr gScreenAddr,gDrawBufferPtr;
extern long gScreenRowBytes;
/****************************/
/* PROTOTYPES */
/****************************/
void ProfileIt(void);
static void BlitBufferToScreen(void);
/****************************/
/* CONSTANTS */
/****************************/
/****************************/
/* VARIABLES */
/****************************/
/********************* PROFILE IT *********************/
//
// Calls the blitter routine 1000 times and does a
// beep at the beginning and end so you can time in
// on a stopwatch.
//
void ProfileIt(void)
{
long i;
SysBeep(0); // MAKE 1ST BEEP SOUND
for (i=0; i < 1000L; i++) // blit the buffer 1000 times
BlitBufferToScreen();
SysBeep(0); // MAKE 2ND BEEP SOUND
}
/*************** BLIT BUFFER TO SCREEN ****************/
//
// This is a completely un-optimized blitter routine which
// will blit the 640x480 buffer to the screen.
//
// On a PowerMac 6100/60 it takes approximately 23 seconds
// to execute this 1000 times.
//
static void BlitBufferToScreen(void)
{
long x,y;
long *destPtr,*srcPtr;
Ptr destStartPtr;
srcPtr = (long *)gDrawBufferPtr; // get ptr to start of buffer
destStartPtr = gScreenAddr; // get ptr to start of scan line
for(y=0; y < 480; y++)
{
destPtr = (long *)destStartPtr; // set destPtr to start of line
for (x=0; x < (640/4); x++) // copy a line with 4-byte longs
*destPtr++ = *srcPtr++;
destStartPtr += gScreenRowBytes; // skip to next scan line
}
}